<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Bezdelnick
 * Date: 23.03.13
 * Time: 19:52
 * To change this template use File | Settings | File Templates.
 */
$PATH = Config::getInstance()->getBasePath();
require_once("$PATH/dao/AbstractDao.php");
require_once("$PATH/controller/GenreController.php");

class GenreDao extends AbstractDao
{
    function __construct()
    {
        $this->controller = new GenreController();

    }

    public function loadByFilmId($id)
    {
        // Create query
        $query =
            "SELECT * FROM genres INNER JOIN rel_film_genre " .
                "ON rel_film_genre.genre_id = genres.id AND rel_film_genre.film_id=" . $id;

        // Load data from database
        $result = mysql_query(
            $query, Config::getInstance()->getDbConnection()
        );

        // Build object's array
        $instances = array();
        while ($row = mysql_fetch_array($result)) {
            $instance = PatternUtil::getInstance()->getObjectFromArray(
                $this->controller, $row);
            array_push($instances, $instance);
        }
        return $instances;
    }
}
